import http from './http.js'
import path from './path.js'

//查看用户信息
export function queryUserMessage(tenantId){
    const params = {
        "tenantId": tenantId
    }
    return http.get(path.queryUserWithTenantById,{params})
}

// 添加商品
export function addProduct(data){
    // const params = {
    //     "brandId": "12",
    //     "brandName": "京东东",
    //     "categoryAttributeEditDTOS": [
    //         {
    //             "delFlag": 0,
    //             "editDetailDTOS": [
    //                 {
    //                     "delFlag": 0,
    //                     "handAddStatus": 0,
    //                     "id": "1234567890",
    //                     "inputList": "红色,黑色",
    //                     "inputType": 0,
    //                     "name": "颜色1",
    //                     "selectType": 0,
    //                     "sort": 0
    //                 }
    //             ],
    //             "id": "",
    //             "name": ""
    //         }
    //     ],
    //     "commodityIntro": "好吃你就多吃点",
    //     "commodityName": "好吃点",
    //     "commodityType": 0,
    //     "commodityUnit": "袋",
    //     "detailHtml": "",
    //     "detailMobileHtml": "",
    //     "imageInfos": [
    //         {
    //             "businessId": "",
    //             "delFlag": 0,
    //             "fileId": "",
    //             "id": "",
    //             "imageName": "",
    //             "imageUrl": "",
    //             "isDefault": true,
    //             "sortNo": 0
    //         }
    //     ],
    //     "productCategoryId": "654321",
    //     "productSn": "",
    //     "shopId": shopid,
    //     "skuStockList": [
    //         {
    //             "pic": "",
    //             "skuCode": "2",
    //             "spDatas": [
    //                 {
    //                     "key": "",
    //                     "value": ""
    //                 }
    //             ]
    //         }
    //     ]
    // }
    return http.post(path.addProduct,data)
}

//获取商品列表
export function getAllProducts(data){
    return http.post(path.getAllProducts,{
        "categoryId": "",
        "commodityName":data.name,
        "endTime": "",
        "pageNo": data.pageNo,
        "pageSize": 10,
        "shopId": sessionStorage.getItem('shopid'),
        "sort": "",
        "sortType": "",
        "startTime": ""
    })
}

//获取商品详细信息
export function getProductDetils(id){
    const params = {
        "id":id
    }
    return http.get(path.getProductDetils,{params})
}

//查看商品的所有sku列表
export function getSkuList(id){
    const params = {
        "commodityId":id
    }
    return http.get(path.getSkuList,{params})
}

//删除商品
export function deleteProduct(id){
    const params = {
        "ids" : id,
        "shopId": sessionStorage.getItem('shopid'),
    }
    return http.delete(path.deleteProduct,{params})
}

//添加库存
export function addStock(formDataList) {
    return http.post(path.addStock, formDataList);
}

//修改库存信息
export function updateStock(formData){
    return http.post(path.updateStock, formData);
}


//查询库存列表
export function getAllStocks(data){
    const params = {
        "commodityName": data.name,
        "pageNo": data.pageNo,
        "pageSize": 10,
        "shopId": sessionStorage.getItem('shopid'),
    }
    return http.get(path.getStocks,{params})
}

//库存列表的删除操作
export function deleteStock(id) {
    const params = {
        "id":id
    }
    return http.get(path.deleteStock,{params})
}

//库存列表的确认操作
export function updateStockStatus(id) {
    const data = {
        "id":id
    }
    return http.post(path.updateStockStatus,data)
}

//商品定价
export function setPrice(formDataList) {
    // console.log(formDataList)
    return http.post(path.setPrice,formDataList)
}

//查看定价单详情
export function getPriceDetail(batchNumber,commodityId) {
    const params = {
        "batchNumber":batchNumber,
        "commodityId":commodityId
    }
    return http.get(path.checkPriceDetail,{params})
}


//获取商品定价列表&&商品上下架列表
export function getProductsPricelist(data) {
     const params = {
        "commodityName": data.name,
        "pageNo": data.pageNo,
         "pageSize": 10,
         "shopId": sessionStorage.getItem('shopid')
    }
     return http.get(path.getProductsPricelist,{params})
}

//商品定价审核
export function surePrice(id) {
    return http.put(path.surePrice,{
        "id":id,
        "state":1
    })
}

//商品上架 or 下架
export function updatePublishStatus(id,status,skucode) {
    return http.put(path.updatePublishStatus,{
        "commodityId": id,
        "publishStatus": status,
        "skuCode": skucode
    })
}

//批量商品上架 or 下架
export function updateBatchPublishStatus(data) {
    return http.put(path.updateBatchPublishStatus,data)
}

//设置副标题
export function setSubTitle(id,skucode,subTitle) {
    return http.put(path.setSubTitle,{
        "commodityId": id,
        "skuCode": skucode,
        "subTitle": subTitle
    })
}

// 获取待发货订单列表
export function getToBeShippedOrders(data){
    // console.log("打印待发货订单列表的请求数据信息")
    // console.log(data)
    const params = {
        "shopId":data.shopId,
        "orderTitle":data.name,
        "orderStatus":2,
        "pageNo": data.pageNo,
        "pageSize": 10
        }
    return http.get(path.getOrders,{params});
}

// 获取订单列表
export function getAllOrders(data){
    const params = {
        "shopId":sessionStorage.getItem('shopid'),
        "pageNo": data.pageNo,
        "orderStatus":data.orderStatus,
        "pageSize": 10
        }
    return http.get(path.getOrders,{params});
}

//获取待发货订单详情
export function getToBeShippedOrderDetail(orderId){
    const params = {
        "orderState":2,
        "orderId": orderId
        }
    return http.get(path.getOrderDeatil,{params})
}

//获取已发货订单详情
export function getShippedOrderDetail(orderId){
    const params = {
        "orderState":3,
        "orderId": orderId
        }
    return http.get(path.getOrderDeatil,{params})
}

//获取退换货列表
export function returnList(data){
    return http.post(path.returnList,{
        "commodityName": data.name,
        "pageNo": data.pageNo,
        "pageSize": 10,
        "shopId": sessionStorage.getItem('shopid')  // 商铺id
    })
}

// 获取咨询回复
export function getConsultReply(data){
    const params = {
            "content":data.content,
            "shopId":sessionStorage.getItem('shopid'),
            "pageNo":data.pageNo,
            "pageSize":10
        }
    return http.get(path.getConsultReply,{params})
}

// 添加咨询回复
export function addConsultReply(Data){
    const params = {
        "parentId": "-1",
        "replayContent": Data.replayContent,
        "replyAvatar": "",
	    "replyUserId": "",
        "replyUserNickname": "test",
        "seekAdviceId": Data.seekAdviceId 
    }
    return http.post(path.addConsultReply,params)
}

// 查询当前咨询所有回复
export function getAllreply(Data){
    const params = {
        "id":Data
    }
    return http.get(path.getAllReply,{params});
}

// 获取商品分类列表
export function getCategoryList(){
    const params = {
        "catName":"",
        "parentId":""
    }
    return http.get(path.getCategoryList,{params})
}

// 获取商品分类结构树
export function getCategoryListTree(){
    const params = {
        "catName":"",
        "parentId":""
    }
    return http.get(path.getCategoryListTree,{params})
}

// 获取品牌
export function getBrand(status){
    const params = {
        "status":status,
    }
    return http.get(path.getBrand,{params})
}

// 订单详情发货
export function deliverGoods(data){
    const params = {
        "orderId":data.id,
        "sendCompany": data.postName,
        "sendOrderNo": data.postNumber,
    }
    console.log(params)
    return http.put(path.deliverGoods,params)
}

// 获取地址
export function getAddressList(pageNo){
    const params =new URLSearchParams();
    params.append("pageNo",pageNo);
    params.append("pageSize",10);
    console.log(params)
    return http.get(path.getplaceList,{params},{headers: { 'Content-Type': 'application/x-www-form-urlencoded'}} )
}

// 获取该分类的数据
export function getCategoryData(id){
    const params = {
        "id": id,
    }
    return http.get(path.getCategoryData,{params})
}

//修改收货信息接口
export function updateAddress(data) {
    const params = {
        "city": "",
        "defaultStatus": 0,
        "detailAddress": data.detailAddress,
        "id": data.id,
        "name": data.name,
        "phone": data.phone,
        "postCode": "",
        "province": "",
        "region": ""
    }
   return http.put(path.changedetail, params)
}

//修改待发地址的接口
export function updateToshippedAddress(data) {
    const params = {
        "addressId": data.addressId,
        "orderId": data.orderId
    }
    return http.put(path.changetoshippedAddress, params)
}

//获取退换货详情
export function getreturnchangeDetail(id){
    return http.get(path.getreturnchangeDetail,{id})
}

// 审批
export function approveById(id) {
    const params = {
        "id" : id,
    }
    return http.post(path.approveById, params);
}
  
// 确认收货
export function confirmReceipt(id) {
    const params = {
        "id" : id,
    }
    return http.post(path.confirmReceipt, params);
}

// 取消退换货订单
export function cancelById(id){
    const params = {
        "id" : id,
    }
    return http.post(path.cancelById,params);
}

// 生成二维码
export function getQRcode(data){
    const params = {
        "orderNumber":data.orderNumber,
        "payChannel":data.payChannel
     }
     console.log(params);
    return http.get(path.getQRcode,{params})
}

//获取商品单位列表
export function getCommodityunitList(){
    return http.get(path.getCommodityunitList)
}

// 添加商品单位
export function addCommodityunit(unit){
    const params = {
        "unit" : unit,
    }
    return http.post(path.addCommodityunit,params);
}

//品牌管理探窗新增品牌
export function addBrand(data){
    const params = {
        "applyType": 2,
        "brandName": data.brandName,
        "letter":data.letter,
        "logo": data.logo
    }
    return http.post(path.applybrand,params)
}

//品牌管理弹窗上传图片
export function uploadImg(data){
    const files= data
    return http.post(path.uploadImg,files)
}

//切换企业
export function changecompanies(id){
    const params = {
        "tenantIdSelect": id,
    }
    return http.post(path.changecompanies,params)
}